package Duoxiancheng.FutureMode;

public class FutureData implements Data{
    private Data realData;
    private Boolean isReady=false;
    private Boolean flag = false;

    public void setResult(Data realData) {
        synchronized (flag){
            if (isReady)
                return;
            this.realData = realData;
            this.isReady  = true;
            flag.notifyAll();
        }



    }

    @Override
    public  String getResult() throws InterruptedException {
        synchronized(flag){
            while (!isReady){
                System.out.println("wait");
                flag.wait();
            }
        }
        return realData.getResult();
    }

//    public synchronized void setResult(Data realData) {
//        if (isReady)
//            return;
//        this.realData = realData;
//        this.isReady  = true;
//        notifyAll();
//
//
//    }
//
//    @Override
//    public synchronized String getResult() throws InterruptedException {
//        while (!isReady){
//            wait();
//        }
//        return realData.getResult();
//    }
}
